package com.sas.common.converter;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = false)
public class CustomerStatusConverter implements AttributeConverter<Integer, String> {

    @Override
    public String convertToDatabaseColumn(Integer attribute) {
        if (attribute == null) return null;
        // 1: ACTIVE, 0: 非活跃 -> INACTIVE
        return attribute == 1 ? "ACTIVE" : "INACTIVE";
    }

    @Override
    public Integer convertToEntityAttribute(String dbData) {
        if (dbData == null) return null;
        switch (dbData) {
            case "ACTIVE":
                return 1;
            case "INACTIVE":
            case "DISCHARGED":
            case "TRANSFERRED":
            case "DECEASED":
                return 0;
            default:
                return 0;
        }
    }
}